aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/account/[id]/+page.server.ts
blob: b91a07886cf1366d4f8971a9b80b05591aa754c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { error, redirect } from "@sveltejs/kit";
import { auth, get, post, fd } from "$lib/utils";

export const load = async ({ cookies, params }) => {
	const account = await get(`/account/${params.id}`, auth(cookies));
	return { account };
};

export const actions = {
	default: async ({ cookies, params, request }) => {
		const { id } = params;
		const body = await fd(request);
		const username = cookies.get("username");

		try {
			await post(`/account/${id}`, body, auth(cookies));
		} catch (e: any) {
			console.log(e);
			error(400, { message: e.message });
		}

		redirect(303, `/${username}`);
	},
};